package com.design.yjx.iterator.iterator;

import java.util.Iterator;

/**
 * @author yuanjianxin
 * @date 2017/8/22 15:10
 */
public class Waitress {
    private Menu dinerMenu;
    private Menu pancakeHouseMenu;
    private Menu cafeMenu;

    public Waitress(Menu dinerMenu, Menu pancakeHouseMenu,Menu cafeMenu) {
        this.dinerMenu = dinerMenu;
        this.pancakeHouseMenu = pancakeHouseMenu;
        this.cafeMenu = cafeMenu;
    }

    public void printMenu() {
        Iterator dinerMenuIterator = dinerMenu.createIterator();
        Iterator pancakeHouseMenuIterator = pancakeHouseMenu.createIterator();
        Iterator cafeMenuIterator = cafeMenu.createIterator();
        System.out.println("---菜单1---");
        this.printMenu(dinerMenuIterator);
        System.out.println("---菜单2---");
        this.printMenu(pancakeHouseMenuIterator);
        System.out.println("---菜单3---");
        this.printMenu(cafeMenuIterator);
    }

    private void printMenu(Iterator iterator) {
        while (iterator.hasNext()) {
           MenuItem menuItem = (MenuItem) iterator.next();
            System.out.println(menuItem);
        }
    }
}
